#coding=utf-8
from stutils import *
from stratedy import *
from stutils import *
set_django_environ()
from stdj.stock.models import *

con = get_con()
RPDIR = '/home/jay/report/hpjump'
rp_head = ['代码', '名称', '日期', '跳空幅度', '1天收益', '3天收益', '5天收益', '10天收益']
def makereport(con, exdate):
    rs = dict(get_jump(con, exdate, 1))
    
    es = []
    cs = rs.keys()
    for c in cs:
        s = Share.objects.get(code=c)
        e = s.exday_set.get(date=exdate)
        es.append(e)
        
    data = []    
    for e in es:
        s = e.share
        p = e.price
        data.append([s.code.encode('u8'), s.name.encode('u8'), p.date.encode('u8'), rs[s.code], 
                     afternday_change(e, 2), afternday_change(e, 3),
                     afternday_change(e, 5), afternday_change(e, 10)]  )
   
    fn = '%s/%s.csv'%(RPDIR, exdate)
    data2csv(data, rp_head, fn)
    
if __name__ == '__main__':
    exdays = ['2007-12-03',
 '2007-12-04',
 '2007-12-05',
 '2007-12-06',
 '2007-12-07',
 '2007-12-10',
 '2007-12-11',
 '2007-12-12',
 '2007-12-13',
 '2007-12-14',
 '2007-12-17',
 '2007-12-18',
 '2007-12-19',
 '2007-12-20',
 '2007-12-21',
 '2007-12-24',
 '2007-12-25',
 '2007-12-26',
 '2007-12-27',
 '2007-12-28',
 '2008-01-02',
 '2008-01-03',
 '2008-01-04',
 '2008-01-07',
 '2008-01-08']
    for e in exdays:
        makereport(con, e)
        print e
